/**
* 
* Copyright [2007] [Sunny Liu]
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*/
package ${appConfig.outputPackageName}.trans;


import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

<#list entities as entity>
import ${appConfig.outputPackageName}.model.${entity.javaName};
import ${appConfig.outputPackageName}.dao.${entity.javaName}DAO;
</#list>


public class TransactionProxyImpl implements TransactionProxy
{
	
	private static Logger log = LoggerFactory.getLogger(TransactionProxyImpl.class);
	
	<#list entities as entity>	
		${entity.javaName}DAO  ${entity.normalizedJavaName}DAO;
	</#list>
	
	
	<#list entities as entity>
	
	//=============================================================================
	//    DAO method defined for domain object 
	//    ${appConfig.outputPackageName}.model.${entity.javaName};
	//=============================================================================
	
	public <#if appConfig.viewType == "ws" || appConfig.viewType == "webservice">${entity.javaName}[]<#else>List</#if> findAll${entity.javaName}()
	{
		if(log.isDebugEnabled()) log.debug("Entering findAll${entity.javaName}()");
		List ret = get${entity.javaName}DAO().findAll${entity.javaName}();		
		if(log.isDebugEnabled()) log.debug("Exiting findAll${entity.javaName}()");	
		<#if appConfig.viewType == "ws" || appConfig.viewType == "webservice">
		${entity.javaName}[] aRet=null;
		if(ret!=null){
			aRet = new ${entity.javaName}[ret.size()];
		    ret.toArray(aRet);
		}
		return aRet;
		<#else>
		return ret;
		</#if>
	
	}
	
	
	public ${entity.javaName} add${entity.javaName}(${entity.javaName} model)
	{
		if(log.isDebugEnabled()) log.debug("Entering add${entity.javaName}(${entity.javaName} model) model=" + model);
		${entity.javaName} ret = get${entity.javaName}DAO().add${entity.javaName}(model);
		if(log.isDebugEnabled()) log.debug("Exiting add${entity.javaName}(${entity.javaName} model) model=" + model);	
		return ret;	
	}
	
	public ${entity.javaName} update${entity.javaName}(${entity.javaName} model)
	{
		if(log.isDebugEnabled()) log.debug("Entering add${entity.javaName}(${entity.javaName} model) model=" + model);
		${entity.javaName} ret = get${entity.javaName}DAO().update${entity.javaName}(model);
		if(log.isDebugEnabled()) log.debug("Exiting add${entity.javaName}(${entity.javaName} model) model=" + model);	
		return ret;	
	}
	
	public ${entity.javaName} delete${entity.javaName}(${entity.javaName} model)
	{
		if(log.isDebugEnabled()) log.debug("Entering add${entity.javaName}(${entity.javaName} model) model=" + model);
		${entity.javaName} ret = get${entity.javaName}DAO().delete${entity.javaName}(model);
		if(log.isDebugEnabled()) log.debug("Exiting add${entity.javaName}(${entity.javaName} model) model=" + model);	
		return ret;	
	}
	
	<#if entity.hasPrimaryKey >	
	public ${entity.javaName} find${entity.javaName}ByKey(<#list entity.primaryKeyColumns as attribute>${attribute.javaType} ${attribute.javaName} <#if attribute_has_next>, </#if></#list>)
	{
		if(log.isDebugEnabled()) log.debug("Entering find${entity.javaName}ByKey() Primarykey=" + <#list entity.primaryKeyColumns as attribute>${attribute.javaName} <#if attribute_has_next> +  "|" + </#if></#list>);
		${entity.javaName} ret = get${entity.javaName}DAO().find${entity.javaName}ByKey(<#list entity.primaryKeyColumns as attribute>${attribute.javaName} <#if attribute_has_next>, </#if></#list>);		
		if(log.isDebugEnabled()) log.debug("Exiting find${entity.javaName}ByKey() Primarykey=" + <#list entity.primaryKeyColumns as attribute>${attribute.javaName} <#if attribute_has_next> +  "|" + </#if></#list>);	
		return ret;
	
	}
	
	public ${entity.javaName} find${entity.javaName}ByKey(${entity.javaName} ${entity.normalizedJavaName})
	{
		if(log.isDebugEnabled()) log.debug("Entering find${entity.javaName}ByKey() Primarykey=" + ${entity.normalizedJavaName});
		${entity.javaName} ret = get${entity.javaName}DAO().find${entity.javaName}ByKey(${entity.normalizedJavaName});		
		if(log.isDebugEnabled()) log.debug("Exiting find${entity.javaName}ByKey() Primarykey=" + ${entity.normalizedJavaName});	
		return ret;	
	}
	
	public ${entity.javaName} delete${entity.javaName}ByKey(<#list entity.primaryKeyColumns as attribute>${attribute.javaType} ${attribute.javaName} <#if attribute_has_next>, </#if></#list>)
	{
		if(log.isDebugEnabled()) log.debug("Entering find${entity.javaName}ByKey() Primarykey=" + <#list entity.primaryKeyColumns as attribute>${attribute.javaName} <#if attribute_has_next> +  "|" + </#if></#list>);
		${entity.javaName} ret = get${entity.javaName}DAO().delete${entity.javaName}ByKey(<#list entity.primaryKeyColumns as attribute>${attribute.javaName} <#if attribute_has_next>, </#if></#list>);		
		if(log.isDebugEnabled()) log.debug("Exiting find${entity.javaName}ByKey() Primarykey=" + <#list entity.primaryKeyColumns as attribute>${attribute.javaName} <#if attribute_has_next> +  "|" + </#if></#list>);	
		return ret;
	}
	</#if>
	//=============================================================================
	//    end of definition of domain object of
	//   ${appConfig.outputPackageName}.model.${entity.javaName};
	//=============================================================================
	
	
	</#list>
	
	
	
	//=============================================================================
	//    DAO class getter and setter methods. 
	//    
	//=============================================================================
	
	<#list entities as entity>	
		 
		public void set${entity.javaName}DAO(${entity.javaName}DAO  ${entity.normalizedJavaName}DAO)
		{
			this.${entity.normalizedJavaName}DAO = ${entity.normalizedJavaName}DAO;
		}
		
		public ${entity.javaName}DAO  get${entity.javaName}DAO()
		{
			return this.${entity.normalizedJavaName}DAO;
		}
	
	</#list>
	
	
	

}